package com.qiuyuliantu.guide.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qiuyuliantu.common.annotation.Log;
import com.qiuyuliantu.common.core.controller.BaseController;
import com.qiuyuliantu.common.core.domain.AjaxResult;
import com.qiuyuliantu.common.enums.BusinessType;
import com.qiuyuliantu.guide.domain.GuideCookbookClass;
import com.qiuyuliantu.guide.service.IGuideCookbookClassService;
import com.qiuyuliantu.common.utils.poi.ExcelUtil;
import com.qiuyuliantu.common.core.page.TableDataInfo;

/**
 * 美食菜谱分类Controller
 *
 * @author lmx
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/guide/cookbook")
public class GuideCookbookClassController extends BaseController
{
    @Autowired
    private IGuideCookbookClassService guideCookbookClassService;

    /**
     * 查询美食菜谱分类列表
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:list')")
    @GetMapping("/list")
    public TableDataInfo list(GuideCookbookClass guideCookbookClass)
    {
        startPage();
        List<GuideCookbookClass> list = guideCookbookClassService.selectGuideCookbookClassList(guideCookbookClass);
        return getDataTable(list);
    }
    /**
     * 随机推送美食菜谱
     */
    @GetMapping("/tool/randomFood")
    public TableDataInfo randomFoodList(GuideCookbookClass guideCookbookClass)
    {
        startPage();
        List<GuideCookbookClass> list = guideCookbookClassService.selectGuideCookbookClassList(guideCookbookClass);
        return getDataTable(list);
    }
    /**
     * 导出美食菜谱分类列表
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:export')")
    @Log(title = "美食菜谱分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GuideCookbookClass guideCookbookClass)
    {
        List<GuideCookbookClass> list = guideCookbookClassService.selectGuideCookbookClassList(guideCookbookClass);
        ExcelUtil<GuideCookbookClass> util = new ExcelUtil<GuideCookbookClass>(GuideCookbookClass.class);
        util.exportExcel(response, list, "美食菜谱分类数据");
    }

    /**
     * 获取美食菜谱分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(guideCookbookClassService.selectGuideCookbookClassById(id));
    }

    /**
     * 新增美食菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:add')")
    @Log(title = "美食菜谱分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GuideCookbookClass guideCookbookClass)
    {
        return toAjax(guideCookbookClassService.insertGuideCookbookClass(guideCookbookClass));
    }

    /**
     * 修改美食菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:edit')")
    @Log(title = "美食菜谱分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GuideCookbookClass guideCookbookClass)
    {
        return toAjax(guideCookbookClassService.updateGuideCookbookClass(guideCookbookClass));
    }

    /**
     * 删除美食菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('guide:cookbook:remove')")
    @Log(title = "美食菜谱分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(guideCookbookClassService.deleteGuideCookbookClassByIds(ids));
    }
}
